package com.yuantu.judiciary.controller;

import com.yuantu.judiciary.common.Response;
import com.yuantu.judiciary.common.ResponseFactory;
import com.yuantu.judiciary.model.enums.UserFollowType;
import com.yuantu.judiciary.model.form.GetQueryInfoForm;
import com.yuantu.judiciary.model.vo.PageVO;
import com.yuantu.judiciary.model.vo.UserFollowDynamicVO;
import com.yuantu.judiciary.model.vo.UserFollowEnterpriseVO;
import com.yuantu.judiciary.model.vo.UserFollowPersonVO;
import com.yuantu.judiciary.service.IUserFollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户关注模块
 *
 * @author syw
 * @since 2023-06-24
 **/
@RestController
@RequestMapping(value = "/user-follow")
@Api(tags = "用户关注模块")
@RequiredArgsConstructor
public class UserFollowController extends BaseController {

    private final IUserFollowService userFollowService;

    @ApiOperation(value = "添加关注-企业")
    @PostMapping("/add/enterprise")
    public Response<Boolean> addEnterprise(@RequestBody @Validated GetQueryInfoForm form) {
        Long accountId = getLoginAccount().getAccountId();
        return ResponseFactory.okResponse(userFollowService.add(accountId, form, UserFollowType.ENTERPRISE));
    }

    @ApiOperation(value = "添加关注-个人")
    @PostMapping("/add/person")
    public Response<Boolean> addPerson(@RequestBody @Validated GetQueryInfoForm form) {
        Long accountId = getLoginAccount().getAccountId();
        return ResponseFactory.okResponse(userFollowService.add(accountId, form, UserFollowType.PERSON));
    }

    @ApiOperation(value = "取消关注")
    @PostMapping("/cancel")
    public Response<Boolean> cancelEnterprise(@RequestBody @Validated GetQueryInfoForm form) {
        Long accountId = getLoginAccount().getAccountId();
        return ResponseFactory.okResponse(userFollowService.cancel(accountId, form));
    }

    @ApiOperation(value = "获取关注企业列表")
    @PostMapping("/get/enterprise/page")
    public Response<PageVO<UserFollowEnterpriseVO>> getEnterprisePage(@PageableDefault Pageable pageable) {
        Long accountId = getLoginAccount().getAccountId();
        return ResponseFactory.okResponse(userFollowService.getFollowEnterprisePage(accountId, pageable));
    }

    @ApiOperation(value = "获取关注个人列表")
    @PostMapping("/get/person/page")
    public Response<PageVO<UserFollowPersonVO>> getPersonPage(@PageableDefault Pageable pageable) {
        Long accountId = getLoginAccount().getAccountId();
        return ResponseFactory.okResponse(userFollowService.getFollowPersonPage(accountId, pageable));
    }

    @ApiOperation(value = "获取关注个数")
    @PostMapping("/get/count")
    public Response<Integer> getFollowCount() {
        Long accountId = getLoginAccount().getAccountId();
        return ResponseFactory.okResponse(userFollowService.getFollowCount(accountId));
    }

    @ApiOperation(value = "获取关注动态")
    @PostMapping("/get/dynamic")
    public Response<PageVO<UserFollowDynamicVO>> getFollowDynamic(@PageableDefault Pageable pageable) {
        Long accountId = getLoginAccount().getAccountId();
        return ResponseFactory.okResponse(userFollowService.getFollowDynamic(accountId, pageable));
    }

}
